package com.hub.controller;

import com.hub.service.IAuthRoleService;
import com.hub.dto.PageParam;
import com.hub.dto.auth.RoleProfileParam;
import com.hub.entity.AuthRole;
import com.hub.utils.ApiResultObject;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * AuthRoleController
 *
 * @description:
 * @author hub
 * @create: 2020-05-14 13:31
 */
@RestController
@RequestMapping("/roles")
public class AuthRoleController {

    @Autowired
    private IAuthRoleService authRoleService;

    @RequiresPermissions("Role")
    @ApiOperation("获取角色列表")
    @PostMapping("/list")
    public ApiResultObject getList(@RequestBody PageParam<AuthRole> pageParam){
        return ApiResultObject.success(authRoleService.getList(pageParam.getPage(), pageParam.getParams()));
    }

    @RequiresPermissions("Role")
    @ApiOperation("获取所有角色")
    @PostMapping("/all")
    public ApiResultObject all(){
        return authRoleService.all();
    }

    @RequiresPermissions("Role")
    @ApiOperation("获取菜单树列表")
    @PostMapping("/getTreeBean")
    public ApiResultObject getTreeBean(){
        return ApiResultObject.success(authRoleService.getTreeBean());
    }

    @RequiresPermissions("Role")
    @ApiOperation("获取角色权限列表")
    @PostMapping("/getRoleProfile")
    public ApiResultObject getList(@RequestParam("roleId") Long roleId){
        return ApiResultObject.success(authRoleService.getRoleProfile(roleId));
    }

    @RequiresPermissions("Role")
    @ApiOperation("创建角色")
    @PostMapping("/create")
    public ApiResultObject createRole(@RequestBody RoleProfileParam param){
        return authRoleService.create(param);
    }

    @RequiresPermissions("Role")
    @ApiOperation("更新权限信息")
    @PostMapping("/modify")
    public ApiResultObject modify(@RequestBody RoleProfileParam param) {
        return authRoleService.modify(param);
    }

    @RequiresPermissions("Role")
    @ApiOperation("删除角色")
    @PostMapping("/delete")
    public ApiResultObject delete(@RequestBody @Valid RoleProfileParam param){
        return authRoleService.delete(param);
    }
}
